class: center, middle, inverse, title-slide .title[ # Phase II: Using Our Toolbox ] .subtitle[ ## Module 7: Birds of a Feather ] .author[ ### Dr. Christopher Kenaley ] .institute[ ### Boston College ] .date[ ### 2024/18/11 ] --- class: inverse, top # In class today ``` ## Warning: package 'ggplot2' was built under R version 4.2.3 ``` <!-- Add icon library --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css"> .pull-left[ Today we'll .... - Consider Linear Mixed-effect Modeling ] .pull-right[  ] --- class: inverse, top <!-- slide 1 --> ## Congrats!  --- class: inverse, top <!-- slide 1 --> ## Linear Mixed-effect Modeling .pull-left[ - Other models assume independence of data - LME included fixed and random effects - Often termed repeated measures - Same model formulae, but + `+(1|random_effect)` ] .pull-right[ ``` r iris %>% group_by(Species) %>% summarise_all(.funs = mean) ``` ``` ## # A tibble: 3 × 5 ## Species Sepal.Length Sepal.Width Petal.Length Petal.Width ## <fct> <dbl> <dbl> <dbl> <dbl> ## 1 setosa 5.01 3.43 1.46 0.246 ## 2 versicolor 5.94 2.77 4.26 1.33 ## 3 virginica 6.59 2.97 5.55 2.03 ``` ] --- class: inverse, top <!-- slide 1 --> ## Linear Mixed-effect Modeling .pull-left[ How do a determine what fixed and random effects are? - Depends on the question + what is independent? + what data are dependent, autocorrelated, linked, etc.? ] .pull-right[ ``` r iris %>% group_by(Species) %>% summarise_all(.funs = mean) ``` ``` ## # A tibble: 3 × 5 ## Species Sepal.Length Sepal.Width Petal.Length Petal.Width ## <fct> <dbl> <dbl> <dbl> <dbl> ## 1 setosa 5.01 3.43 1.46 0.246 ## 2 versicolor 5.94 2.77 4.26 1.33 ## 3 virginica 6.59 2.97 5.55 2.03 ``` --- class: inverse, top <!-- slide 1 --> ## Linear Mixed-effect Modeling .pull-left[ Say our question was, is sepal length different between species? - Species isn't random, it's part of the question ] .pull-right[ ``` r fit <- lm(Sepal.Length~Species,iris) anova(fit) ``` ``` ## Analysis of Variance Table ## ## Response: Sepal.Length ## Df Sum Sq Mean Sq F value Pr(>F) ## Species 2 63.212 31.606 119.26 < 2.2e-16 *** ## Residuals 147 38.956 0.265 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` --- class: inverse, top <!-- slide 1 --> ## Linear Mixed-effect Modeling .pull-left[ Say our question was, is sepal length a function of petal length? - Species is now random, it's not part of the question ] .pull-right[ ``` r fit <- lmer(Sepal.Length~Petal.Length+(1|Species),iris) library(car) Anova(fit) ``` ``` ## Analysis of Deviance Table (Type II Wald chisquare tests) ## ## Response: Sepal.Length ## Chisq Df Pr(>Chisq) ## Petal.Length 193.96 1 < 2.2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ```